<template>
  <div class="create">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/page/book'}">上传</el-breadcrumb-item>
      <el-breadcrumb-item>创建图库</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>创建文档库</span>
    </div>
    <div class="content">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" @submit.native.prevent>
  <el-form-item label="文档库名称" prop="name">
    <el-input v-model="ruleForm.name" prefix-icon="el-icon-s-management" ></el-input>
  </el-form-item>
  <el-form-item label="文档库简介" prop="desc">
    <el-input type="textarea" v-model="ruleForm.desc" placeholder="如：产品设计与研发"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="warning" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
  </el-form>
    </div>
  </el-card>
  </div>
</template>

<script>
import { create } from '@/utils/api/library'
import { getUserProfile } from '@/utils/api/user'
export default {
  name: 'create-book',
  props: {},
  components: {},
  data () {
    return {
      ruleForm: {
        name: '',
        desc: '',
      },
      rules: {
        name: [
          { required: true, message: '请输入抽屉名称', trigger: 'blur' },
        ],
        desc: [
          { required: true, message: '请填写抽屉简介', trigger: 'blur' }
        ]
      },
      dialogImageUrl: '',
      dialogVisible: false,
      disabled: false,
      userInfo: null
    }
  },
  created () {
    getUserProfile().then(res => {
      this.userInfo = res.data.data
    })
  },
  methods: {
    // 创建小组
    submitForm (formName) {
      const data = {
        libname: this.ruleForm.name,
        introduction: this.ruleForm.desc,
        creatorId: this.userInfo.id,
        identity: 'hahaha'
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          create(data).then(res => {
            if (res.data.code === 200) {
              this.$message({
                message: '创建成功',
                type: 'success'
              })
            }
            this.$router.push('/page/book')
          }).catch(err => {
            this.$message.error(err)
          })
        } else {
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    },
    // 照片上传
    handleRemove (file) {
      console.log(file);
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload (file) {
      console.log(file);
    }
  },
}
</script>

<style lang="less" scoped>
  .create{
    width: 100%;
    height: calc(100vh - 150px);
    .box-card {
      width: 60%;
      height: 100%;
      margin: 0px auto;
    }
  }
  /deep/ .el-textarea__inner {
    display: block;
    resize: none;
    padding: 5px 15px;
    line-height: 1.5;
    box-sizing: border-box;
    width: 100%;
    font-size: inherit;
    color: #606266;
    background-color: #FFF;
    background-image: none;
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    height: 80px !important;
}
/deep/ .el-input__prefix, .el-input__suffix {
    position: absolute;
    top: 0;
    height: 100%;
    color: rgb(230, 117, 97);
    text-align: center;
    font-size: 20px;
}
.url{
  -webkit-appearance: none;
    background-color: #FFF;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
}
.clearfix{
  font-size: 26px;
}
</style>
